#include "StageParam.h"

StageParam::StageParam(char * filename)
{

	potatoCount = 0;
	char currentLine[100]; //arbitrary number
	ifstream in(filename);
	if(!in){
		cout << "Cannot open file.";
	}
	in.getline(currentLine, 100); //gets the stage name
	stage = currentLine;

	in.getline(currentLine, 10); //gets time in level
	int temp = atoi( currentLine );
	countdown = temp;

	in.getline(currentLine,10, ' '); //gets x length of level
	temp = atoi( currentLine ); //converts the c string to an int (getline returns cstrings not ints and type casting doesn't work)
	x = temp;
	in.getline(currentLine,10,' '); //gets y length of level
	temp = atoi( currentLine );
	y = temp;
	in.getline(currentLine,10); //gets z length of level
	temp = atoi( currentLine );
	z = temp;

	cout<<stage<<endl<<countdown<<endl<<x<<endl<<y<<endl<<z; 

	//
	//this section will interpret the text file and create the level (floors)
	//
	char currentTile;
	vector<Floor*> temp1 (z);
	vector<vector<Floor*>> temp2 (y);
	vector<vector<vector<Floor*>>> temp7(x);


	//This forloop sets up the vectors for use, its a 3d vector so its important to set this up correctly
	for(int i = 0; i<x ; i++){
		for(int j = 0; j<y; j++){
			for(int k = 0; k<z; k++){

			}
			temp2[j]=(temp1);
		}
		temp7[i]=(temp2);
	}
	//sets this section loads the floors
	for(int k = 0; k<z ; k++){

		if(k!=0) //formats end of lines
			in.getline(currentLine,100);

		for(int j = 0; j<y; j++){
			if(j!=0) //formats end of lines
				in.getline(currentLine,100);

			for(int i = 0; i<x; i++){

				//
				//Section for Loading tiles
				//
				in.get(currentTile);
				if(currentTile == 'Q'){					
					Floor *tempFloor = new Floor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'W'){					
					Floor *tempFloor = new IceFloor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'E'){					
					Floor *tempFloor = new FireFloor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'R'){					
					Floor *tempFloor = new WaterFloor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'T'){					
					Floor *tempFloor = new EmptyFloor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == '8'){					
					Floor *tempFloor = new Stairs(i,j,k,(int)SNORTH); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == '2'){					
					Floor *tempFloor = new Stairs(i,j,k,(int)SSOUTH); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == '6'){					
					Floor *tempFloor = new Stairs(i,j,k,(int)SEAST); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == '4'){					
					Floor *tempFloor = new Stairs(i,j,k,(int)SWEST); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'Y'){					
					Floor *tempFloor = new GravelFloor(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'U'){					
					Floor *tempFloor = new ForcePadFloor(i,j,k,(int)UP); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'I'){					
					Floor *tempFloor = new ForcePadFloor(i,j,k,(int)RIGHT); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'O'){					
					Floor *tempFloor = new ForcePadFloor(i,j,k,(int)DOWN); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'P'){					
					Floor *tempFloor = new ForcePadFloor(i,j,k,(int)LEFT); 
					temp7[i][j][k] = tempFloor;
				}

				else if(currentTile == 'A'){					
					Floor *tempFloor = new WallFloor(i,j,k,(int)WNORTH); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'S'){					
					Floor *tempFloor = new WallFloor(i,j,k,(int)WEAST); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'D'){					
					Floor *tempFloor = new WallFloor(i,j,k,(int)WSOUTH); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'F'){					
					Floor *tempFloor = new WallFloor(i,j,k,(int)WWEST); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == 'H'){					
					Floor *tempFloor = new BlockSwitch(i,j,k); 
					temp7[i][j][k] = tempFloor;
				}
				else if(currentTile == '?'){					
					Floor *tempFloor = new BlockSwitch(i,j,k,1); 
					temp7[i][j][k] = tempFloor;
				}
			}
		}			
	}
	map = temp7;

	//This section will interpret the text file and add objects to the level
	//this includes tallying things such as potato count, taits location and any other relevant info we need
	in.getline(currentLine,100);

	for(int k = 0; k<z ; k++){

		if(k!=0) //formats end of lines
			in.getline(currentLine,100);

		for(int j = 0; j<y; j++){
			if(j!=0) //formats end of lines
				in.getline(currentLine,100);

			for(int i = 0; i<x; i++){
				in.get(currentTile);			
				if(currentTile == '1'){	// no need to store empty spots				

				}
				else if(currentTile=='Q'){
					Object *tempObject = new Tait(i,j,k,map);
					tait = tempObject;
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='W'){
					Object *tempObject = new Exit(i,j,k,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='E'){
					Object *tempObject = new Block(i,j,k,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='X'){
					Object *tempObject = new PickUp(i,j,k,SKATES,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='C'){
					Object *tempObject = new PickUp(i,j,k,BOOTS,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='Z'){
					Object *tempObject = new PickUp(i,j,k,POTATO,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
					potatoCount++;
				}
				else if(currentTile=='T'){
					Object *tempObject = new ImoBlock(i,j,k,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='Y'){
					Object *tempObject = new Bomb(i,j,k,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='U'){
					Object *tempObject = new DissolveBlock(i,j,k,map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='A'){
					Object *tempObject = new Key(i,j,k,(int)REDKEY, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='S'){
					Object *tempObject = new Key(i,j,k,(int)GREENKEY, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='D'){
					Object *tempObject = new Key(i,j,k,(int)YELLOWKEY, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='F'){
					Object *tempObject = new Key(i,j,k,(int)ORANGEKEY, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile==';'){
					Object *tempObject = new Gate(i,j,k,(int)POTATOGATE, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='H'){
					Object *tempObject = new Gate(i,j,k,(int)REDGATE, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='J'){
					Object *tempObject = new Gate(i,j,k,(int)GREENGATE, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='K'){
					Object *tempObject = new Gate(i,j,k,(int)YELLOWGATE, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='L'){
					Object *tempObject = new Gate(i,j,k,(int)ORANGEGATE, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='9'){
					Object *tempObject = new FrogMonster(i,j,k, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='8'){
					Object *tempObject = new AntMonster(i,j,k,UP, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='6'){
					Object *tempObject = new AntMonster(i,j,k,RIGHT, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='2'){
					Object *tempObject = new AntMonster(i,j,k,DOWN, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}
				else if(currentTile=='4'){
					Object *tempObject = new AntMonster(i,j,k,LEFT, map); 
					objects.push_back(tempObject);
					map[i][j][k]->changeObject(tempObject->getType());
				}



			}		
		}
	}
	cout<<"Done Object Load"<<endl;


}

StageParam::StageParam() // never call this
{
}


StageParam::StageParam(int countdown, int potatoCount)
{
}

StageParam::~StageParam(void)
{
}


Object * StageParam::getTait(){return tait;}

int StageParam::getX(){return x;}
int StageParam::getY(){return y;}
int StageParam::getZ(){return z;}



int StageParam::getCountdown()
{
	return countdown;
}

string StageParam::getStage(){
	return stage;
}


int StageParam::getPotatoCount()
{
	return potatoCount;
}

vector<vector<vector<Floor*>>> StageParam::getMap(){return map;}

vector<Object*> StageParam::getObjects(){return objects;}